package com.admin.business.portalWebsite.venusSysBusinessCooperation;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 商业合作表（最新）
 * @create: 2023-11-21 14:18:29
 **/
@Service("venusSysBusinessCooperationService")
@Slf4j
public class VenusSysBusinessCooperationService{

    @Resource
    VenusSysBusinessCooperationDao venusSysBusinessCooperationDao;

    /**
     * 添加商业合作表（最新）,获取id数据
     *
     * @param cdoRequest - id:主键id
     *                   - code:唯一编号
     *                   - user_id:发布者id
     *                   - bus_products_model:产品品牌
     *                   - bus_products_name:产品名称
     *                   - bus_org_type:公司类型
     *                   - bus_assorted_type:配套类型
     *                   - bus_serve_type:服务类型
     *                   - bus_serve_area:服务区域
     *                   - bus_products_img:产品照片
     *                   - bus_products_introduce:产品介绍
     *                   - bus_contact_name:联系人
     *                   - bus_contact_tel:联系电话
     *                   - bus_org_name:公司名称
     *                   - bus_org_address:公司地址
     *                   - view_count:浏览量
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return addVenusSysBusinessCooperation(CDO cdoRequest) {
        venusSysBusinessCooperationDao.addVenusSysBusinessCooperation(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新商业合作表（最新）数据
     *
     * @param cdoRequest - id:主键id
     *                   - code:唯一编号
     *                   - user_id:发布者id
     *                   - bus_products_model:产品品牌
     *                   - bus_products_name:产品名称
     *                   - bus_org_type:公司类型
     *                   - bus_assorted_type:配套类型
     *                   - bus_serve_type:服务类型
     *                   - bus_serve_area:服务区域
     *                   - bus_products_img:产品照片
     *                   - bus_products_introduce:产品介绍
     *                   - bus_contact_name:联系人
     *                   - bus_contact_tel:联系电话
     *                   - bus_org_name:公司名称
     *                   - bus_org_address:公司地址
     *                   - view_count:浏览量
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return updateVenusSysBusinessCooperationById(CDO cdoRequest) {
        venusSysBusinessCooperationDao.updateVenusSysBusinessCooperationById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除商业合作表（最新）数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return deleteVenusSysBusinessCooperationById(CDO cdoRequest){
        int count = venusSysBusinessCooperationDao.deleteVenusSysBusinessCooperationById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除商业合作表（最新）数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return deleteVenusSysBusinessCooperation(CDO cdoRequest) {
        int count = venusSysBusinessCooperationDao.deleteVenusSysBusinessCooperation(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取商业合作表（最新）数据
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusSysBusinessCooperationById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysBusinessCooperationDao.getVenusSysBusinessCooperationById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取商业合作表（最新）数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusSysBusinessCooperationListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysBusinessCooperationDao.getVenusSysBusinessCooperationListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysBusinessCooperationDao.getVenusSysBusinessCooperationCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取商业合作表（最新）数据列表
     *
     * @param cdoRequest - id:主键id
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusSysBusinessCooperationListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysBusinessCooperationDao.getVenusSysBusinessCooperationListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysBusinessCooperationDao.getVenusSysBusinessCooperationCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
